package reference;

import java.lang.ref.WeakReference;

/**
 * @program JavaBase
 * @description: 弱引用
 *  遇到gc就会回收
 * @author: zhanglu
 * @create: 2020-12-13 17:01:00
 */
public class Re03_WeakRefernce {

    public static void main(String[] args) {
        WeakReference<RefernceFinalize> weakReference = new WeakReference<>(new RefernceFinalize());
        System.out.println(weakReference.get());
        System.gc();
        System.out.println(weakReference.get());

        ThreadLocal<RefernceFinalize> local = new ThreadLocal<>();
        RefernceFinalize refernceFinalize = new RefernceFinalize();
        System.out.println(refernceFinalize);
        local.set(refernceFinalize);
        System.out.println(local.get());
        local.remove();
        System.out.println(local.get());
    }

}
